//  代码地址: https://github.com/CoderJsMjLee/JsMjRefresh
//  代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000
#import <UIKit/UIKit.h>
#import <objc/message.h>

// 弱引用
#define JsMjWeakSelf __weak typeof(self) weakSelf = self;

// 日志输出
#ifdef DEBUG
#define JsMjRefreshLog(...) NSLog(__VA_ARGS__)
#else
#define JsMjRefreshLog(...)
#endif

// 过期提醒
#define JsMjRefreshDeprecated(DESCRIPTION) __attribute__((deprecated(DESCRIPTION)))

// 运行时objc_msgSend
#define JsMjRefreshMsgSend(...) ((void (*)(void *, SEL, UIView *))objc_msgSend)(__VA_ARGS__)
#define JsMjRefreshMsgTarget(target) (__bridge void *)(target)

// RGB颜色
#define JsMjRefreshColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]

// 文字颜色
#define JsMjRefreshLabelTextColor JsMjRefreshColor(90, 90, 90)

// 字体大小
#define JsMjRefreshLabelFont [UIFont boldSystemFontOfSize:14]

// 常量
UIKIT_EXTERN const CGFloat JsMjRefreshLabelLeftInset;
UIKIT_EXTERN const CGFloat JsMjRefreshHeaderHeight;
UIKIT_EXTERN const CGFloat JsMjRefreshFooterHeight;
UIKIT_EXTERN const CGFloat JsMjRefreshTrailWidth;
UIKIT_EXTERN const CGFloat JsMjRefreshFastAnimationDuration;
UIKIT_EXTERN const CGFloat JsMjRefreshSlowAnimationDuration;

UIKIT_EXTERN NSString *const JsMjRefreshKeyPathContentOffset;
UIKIT_EXTERN NSString *const JsMjRefreshKeyPathContentSize;
UIKIT_EXTERN NSString *const JsMjRefreshKeyPathContentInset;
UIKIT_EXTERN NSString *const JsMjRefreshKeyPathPanState;

UIKIT_EXTERN NSString *const JsMjRefreshHeaderLastUpdatedTimeKey;

UIKIT_EXTERN NSString *const JsMjRefreshHeaderIdleText;
UIKIT_EXTERN NSString *const JsMjRefreshHeaderPullingText;
UIKIT_EXTERN NSString *const JsMjRefreshHeaderRefreshingText;

UIKIT_EXTERN NSString *const JsMjRefreshTrailerIdleText;
UIKIT_EXTERN NSString *const JsMjRefreshTrailerPullingText;

UIKIT_EXTERN NSString *const JsMjRefreshAutoFooterIdleText;
UIKIT_EXTERN NSString *const JsMjRefreshAutoFooterRefreshingText;
UIKIT_EXTERN NSString *const JsMjRefreshAutoFooterNoMoreDataText;

UIKIT_EXTERN NSString *const JsMjRefreshBackFooterIdleText;
UIKIT_EXTERN NSString *const JsMjRefreshBackFooterPullingText;
UIKIT_EXTERN NSString *const JsMjRefreshBackFooterRefreshingText;
UIKIT_EXTERN NSString *const JsMjRefreshBackFooterNoMoreDataText;

UIKIT_EXTERN NSString *const JsMjRefreshHeaderLastTimeText;
UIKIT_EXTERN NSString *const JsMjRefreshHeaderDateTodayText;
UIKIT_EXTERN NSString *const JsMjRefreshHeaderNoneLastDateText;

// 状态检查
#define JsMjRefreshCheckState \
JsMjRefreshState oldState = self.state; \
if (state == oldState) return; \
[super setState:state];

// 异步主线程执行，不强持有Self
#define JsMjRefreshDispatchAsyncOnMainQueue(x) \
__weak typeof(self) weakSelf = self; \
dispatch_async(dispatch_get_main_queue(), ^{ \
typeof(weakSelf) self = weakSelf; \
{x} \
});
